package logic

import (
	"context"
	"fmt"
	"library/models/mysql"

	"library/library/internal/svc"
	"library/library/library"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddActivityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddActivityLogic {
	return &AddActivityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddActivityLogic) AddActivity(in *library.AddActivityRequest) (*library.AddActivityResponse, error) {
	// todo: add your logic here and delete this line

	activity := mysql.Activity{
		UserId:  in.UserId,
		Title:   in.Title,
		Context: in.Context,
	}
	err := mysql.DB.Debug().Create(&activity).Error
	if err != nil {
		return nil, fmt.Errorf("活动发布失败")
	}

	return &library.AddActivityResponse{Id: int64(activity.ID)}, nil
}
